<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Create new MongoDB Manager</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="mongodb-driver-manager.addsubscriber.html">« MongoDB\Driver\Manager::addSubscriber</a></li>
      <li style="float: right;"><a href="mongodb-driver-manager.createclientencryption.html">MongoDB\Driver\Manager::createClientEncryption »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="class.mongodb-driver-manager.html">MongoDB\Driver\Manager</a></li>
    <li>Create new MongoDB Manager</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="mongodb-driver-manager.construct" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">MongoDB\Driver\Manager::__construct</h1>
  <p class="verinfo">(mongodb &gt;=1.0.0)</p><p class="refpurpose"><span class="refname">MongoDB\Driver\Manager::__construct</span> &mdash; <span class="dc-title">Create new MongoDB Manager</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-mongodb-driver-manager.construct-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">final</span> <span class="modifier">public</span> <span class="methodname"><strong>MongoDB\Driver\Manager::__construct</strong></span>(<span class="methodparam"><span class="type">?</span><span class="type"><span class="type">string</span><span class="type"></span></span> <code class="parameter">$uri</code><span class="initializer"> = <strong><code>null</code></strong></span></span>, <span class="methodparam"><span class="type">?</span><span class="type"><span class="type">array</span><span class="type"></span></span> <code class="parameter">$uriOptions</code><span class="initializer"> = <strong><code>null</code></strong></span></span>, <span class="methodparam"><span class="type">?</span><span class="type"><span class="type">array</span><span class="type"></span></span> <code class="parameter">$driverOptions</code><span class="initializer"> = <strong><code>null</code></strong></span></span>)</div>

  <p class="para rdfs-comment">
   Constructs a new <span class="classname"><a href="class.mongodb-driver-manager.html" class="classname">MongoDB\Driver\Manager</a></span> object with the specified options.
  </p>
  <blockquote class="note"><p><strong class="note">注意</strong>: 
   <span class="simpara">
    Per the <a href="https://github.com/mongodb/specifications/blob/master/source/server-discovery-and-monitoring/server-discovery-and-monitoring.rst#single-threaded-client-construction" class="link external">&raquo;&nbsp;Server Discovery and Monitoring Specification</a>,
    this constructor performs no I/O. Connections will be initialized on demand,
    when the first operation is executed.
   </span>
  </p></blockquote>
  <blockquote class="note"><p><strong class="note">注意</strong>: 
   <span class="simpara">
    When specifying any SSL or TLS URI options via the connection string or
    <code class="parameter">uriOptions</code> parameter, the driver will implicitly
    enable TLS for its connections. To avoid this, either explicitly disable the
    <code class="literal">tls</code> option or don&#039;t specify any TLS options.
   </span>
  </p></blockquote>
  
   <blockquote class="note"><p><strong class="note">注意</strong>: 
    <span class="simpara">
     On Unix platforms, the MongoDB driver is sensitive to scripts that use the
     fork() system call without also calling exec(). Users are advised not to
     re-use <span class="classname"><a href="class.mongodb-driver-manager.html" class="classname">MongoDB\Driver\Manager</a></span> instances in a forked
     child process.
    </span>
   </p></blockquote>

 </div>


 <div class="refsect1 parameters" id="refsect1-mongodb-driver-manager.construct-parameters">
  <h3 class="title">参数</h3>
  <dl>
   
    <dt id="mongodb-driver-manager.construct-uri"><code class="parameter">uri</code></dt>

    <dd>

     <p class="para">
      A <a href="https://www.mongodb.com/docs/manual/reference/connection-string/" class="link external">&raquo;&nbsp;mongodb://</a> connection URI:
      <div class="example-contents">
<div class="txtcode"><pre class="txtcode">mongodb://[username:password@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/[defaultAuthDb][?options]]</pre>
</div>
      </div>

     </p>
     <p class="para">
      For details on supported URI options, see
      <a href="https://www.mongodb.com/docs/manual/reference/connection-string/#connections-connection-options" class="link external">&raquo;&nbsp;Connection String Options</a>
      in the MongoDB manual.
      <a href="https://www.mongodb.com/docs/manual/reference/connection-string/#connection-pool-options" class="link external">&raquo;&nbsp;Connection pool options</a>
      are not supported, as the PHP driver does not implement connection pools.
     </p>
     <p class="para">
      The <code class="parameter">uri</code> is a URL, hence any special characters in
      its components need to be URL encoded according to
      <a href="http://www.faqs.org/rfcs/rfc3986" class="link external">&raquo;&nbsp;RFC 3986</a>. This is particularly
      relevant to the username and password, which can often include special
      characters such as <code class="literal">@</code>, <code class="literal">:</code>, or
      <code class="literal">%</code>. When connecting via a Unix domain socket, the socket
      path may contain special characters such as slashes and must be encoded.
      The <span class="function"><a href="function.rawurlencode.html" class="function">rawurlencode()</a></span> function may be used to encode
      constituent parts of the URI.
     </p>
     <p class="para">
      The <code class="literal">defaultAuthDb</code> component may be used to specify the
      database name associated with the user&#039;s credentials; however the
      <code class="literal">authSource</code> URI option will take priority if specified.
      If neither <code class="literal">defaultAuthDb</code> nor
      <code class="literal">authSource</code> are specified, the <code class="literal">admin</code>
      database will be used by default. The <code class="literal">defaultAuthDb</code>
      component has no effect in the absence of user credentials.
     </p>
    </dd>

   
   
    <dt id="mongodb-driver-manager.construct-urioptions"><code class="parameter">uriOptions</code></dt>

    <dd>

     <p class="para">
      Additional
      <a href="https://www.mongodb.com/docs/manual/reference/connection-string/#connections-connection-options" class="link external">&raquo;&nbsp;connection string options</a>,
      which will overwrite any options with the same name in the
      <code class="parameter">uri</code> parameter.
     </p>
     <p class="para">
      <table class="doctable table">
       <caption><strong>uriOptions</strong></caption>
       
        <thead>
         <tr>
          <th>Option</th>
          <th>Type</th>
          <th>Description</th>
         </tr>

        </thead>

        <tbody class="tbody">
         <tr>
          <td>appname</td>
          <td><span class="type">string</span></td>
          <td>
           <p class="para">
            MongoDB 3.4+ has the ability to annotate connections with metadata
            provided by the connecting client. This metadata is included in the
            server&#039;s logs upon establishing a connection and also recorded in
            slow query logs when database profiling is enabled.
           </p>
           <p class="para">
            This option may be used to specify an application name, which will
            be included in the metadata. The value cannot exceed 128 characters
            in length.
           </p>
          </td>
         </tr>

         <tr>
          <td>authMechanism</td>
          <td><span class="type">string</span></td>
          <td>
           <p class="para">
            The authentication mechanism that MongoDB will use to authenticate
            the connection. For additional details and a list of supported
            values, see
            <a href="https://www.mongodb.com/docs/manual/reference/connection-string/#urioption.authMechanism" class="link external">&raquo;&nbsp;Authentication Options</a>
            in the MongoDB manual.
           </p>
          </td>
         </tr>

         <tr>
          <td>authMechanismProperties</td>
          <td><span class="type">array</span></td>
          <td>
           <p class="para">
            Properties for the selected authentication mechanism. For additional
            details and a list of supported properties, see the
            <a href="https://github.com/mongodb/specifications/blob/master/source/auth/auth.rst#auth-related-options" class="link external">&raquo;&nbsp;Driver Authentication Specification</a>.
           </p>
           <blockquote class="note"><p><strong class="note">注意</strong>: 
            <span class="simpara">
             When not specified in the URI string, this option is expressed as
             an array of key/value pairs. The keys and values in this array
             should be strings.
            </span>
           </p></blockquote>
          </td>
         </tr>

         <tr>
          <td>authSource</td>
          <td><span class="type">string</span></td>
          <td>
           <p class="para">
            The database name associated with the user&#039;s credentials. Defaults
            to the database component of the connection URI, or the
            <code class="literal">admin</code> database if both are unspecified.
           </p>
           <p class="para">
            For authentication mechanisms that delegate credential storage to
            other services (e.g. GSSAPI), this should be
            <code class="literal">&quot;$external&quot;</code>.
           </p>
          </td>
         </tr>

         <tr>
          <td>canonicalizeHostname</td>
          <td><span class="type">bool</span></td>
          <td>
           <p class="para">
            If <strong><code>true</code></strong>, the driver will resolve the real hostname for the server
            IP address before authenticating via SASL. Some underlying GSSAPI
            layers already do this, but the functionality may be disabled in
            their config (e.g. <code class="literal">krb.conf</code>). Defaults to
            <strong><code>false</code></strong>.
           </p>
           <p class="para">
            This option is a deprecated alias for the
            <code class="literal">&quot;CANONICALIZE_HOST_NAME&quot;</code> property of the
            <code class="literal">&quot;authMechanismProperties&quot;</code> URI option.
           </p>
          </td>
         </tr>

         <tr>
          <td>compressors</td>
          <td><span class="type">string</span></td>
          <td>
           <p class="para">
            A prioritized, comma-delimited list of compressors that the client
            wants to use. Messages are only compressed if the client and server
            share any compressors in common, and the compressor used in each
            direction will depend on the individual configuration of the server
            or driver. See the
            <a href="https://github.com/mongodb/specifications/blob/master/source/compression/OP_COMPRESSED.rst#compressors" class="link external">&raquo;&nbsp;Driver Compression Specification</a>
            for more information.
           </p>
          </td>
         </tr>

         <tr id="mongodb-driver-manager.construct-urioptions.connecttimeoutms">
          <td>connectTimeoutMS</td>
          <td><span class="type">int</span></td>
          <td>
           <p class="para">
            The time in milliseconds to attempt a connection before timing out.
            Defaults to 10,000 milliseconds.
           </p>
          </td>
         </tr>

         <tr>
          <td>directConnection</td>
          <td><span class="type">bool</span></td>
          <td>
           <p class="para">
            This option can be used to control replica set discovery behavior
            when only a single host is provided in the connection string. By
            default, providing a single member in the connection string will
            establish a direct connection or discover additional members
            depending on whether the <code class="literal">&quot;replicaSet&quot;</code> URI option
            is omitted or present, respectively. Specify <strong><code>false</code></strong> to force
            discovery to occur (if <code class="literal">&quot;replicaSet&quot;</code> is omitted)
            or specify <strong><code>true</code></strong> to force a direct connection (if
            <code class="literal">&quot;replicaSet&quot;</code> is present).
           </p>
          </td>
         </tr>

         <tr>
          <td>gssapiServiceName</td>
          <td><span class="type">string</span></td>
          <td>
           <p class="para">
            Set the Kerberos service name when connecting to Kerberized MongoDB
            instances. This value must match the service name set on MongoDB
            instances (i.e.
            <a href="https://www.mongodb.com/docs/manual/reference/parameters/#param.saslServiceName" class="link external">&raquo;&nbsp;saslServiceName</a>
            server parameter). Defaults to <code class="literal">&quot;mongodb&quot;</code>.
           </p>
           <p class="para">
            This option is a deprecated alias for the
            <code class="literal">&quot;SERVICE_NAME&quot;</code> property of the
            <code class="literal">&quot;authMechanismProperties&quot;</code> URI option.
           </p>
          </td>
         </tr>

         <tr>
          <td>heartbeatFrequencyMS</td>
          <td><span class="type">int</span></td>
          <td>
           <p class="para">
            Specifies the interval in milliseconds between the driver&#039;s checks
            of the MongoDB topology, counted from the end of the previous check
            until the beginning of the next one. Defaults to 60,000
            milliseconds.
           </p>
           <p class="para">
            Per the
            <a href="https://github.com/mongodb/specifications/blob/master/source/server-discovery-and-monitoring/server-discovery-and-monitoring.rst#heartbeatfrequencyms" class="link external">&raquo;&nbsp;Server Discovery and Monitoring Specification</a>,
            this value cannot be less than 500 milliseconds.
           </p>
          </td>
         </tr>

         <tr>
          <td>journal</td>
          <td><span class="type">bool</span></td>
          <td>
           <p class="para">
            Corresponds to the default write concern&#039;s
            <code class="parameter">journal</code> parameter. If <strong><code>true</code></strong>, writes will
            require acknowledgement from MongoDB that the operation has been
            written to the journal. For details, see
            <span class="classname"><a href="class.mongodb-driver-writeconcern.html" class="classname">MongoDB\Driver\WriteConcern</a></span>.
           </p>
          </td>
         </tr>

         <tr>
          <td>loadBalanced</td>
          <td><span class="type">bool</span></td>
          <td>
           <p class="para">
            Specifies whether the driver is connecting to a MongoDB cluster
            through a load balancer. If <strong><code>true</code></strong>, the driver may only connect to a
            single host (specified by either the connection string or SRV
            lookup), the <code class="literal">&quot;directConnection&quot;</code> URI option
            cannot be <strong><code>true</code></strong>, and the <code class="literal">&quot;replicaSet&quot;</code> URI option
            must be omitted. Defaults to <strong><code>false</code></strong>.
           </p>
          </td>
         </tr>

         <tr>
          <td>localThresholdMS</td>
          <td><span class="type">int</span></td>
          <td>
           <p class="para">
            The size in milliseconds of the latency window for selecting among
            multiple suitable MongoDB instances while resolving a read
            preference. Defaults to 15 milliseconds.
           </p>
          </td>
         </tr>

         <tr>
          <td>maxStalenessSeconds</td>
          <td><span class="type">int</span></td>
          <td>
           <p class="para">
            Corresponds to the read preference&#039;s
            <code class="literal">&quot;maxStalenessSeconds&quot;</code>. Specifies, in seconds, how
            stale a secondary can be before the client stops using it for read
            operations. By default, there is no maximum staleness and clients
            will not consider a secondary’s lag when choosing where to direct a
            read operation. For details, see
            <span class="classname"><a href="class.mongodb-driver-readpreference.html" class="classname">MongoDB\Driver\ReadPreference</a></span>.
           </p>
           <p class="para">
            If specified, the max staleness must be a signed 32-bit integer
            greater than or equal to
            <strong><code>MongoDB\Driver\ReadPreference::SMALLEST_MAX_STALENESS_SECONDS</code></strong>
            (i.e. 90 seconds).
           </p>
          </td>
         </tr>

         <tr>
          <td>password</td>
          <td><span class="type">string</span></td>
          <td>
           The password for the user being authenticated. This option is useful
           if the password contains special characters, which would otherwise
           need to be URL encoded for the connection URI.
          </td>
         </tr>

         <tr>
          <td>readConcernLevel</td>
          <td><span class="type">string</span></td>
          <td>
           Corresponds to the read concern&#039;s <code class="parameter">level</code>
           parameter. Specifies the level of read isolation. For details, see
           <span class="classname"><a href="class.mongodb-driver-readconcern.html" class="classname">MongoDB\Driver\ReadConcern</a></span>.
          </td>
         </tr>

         <tr>
          <td>readPreference</td>
          <td><span class="type">string</span></td>
          <td>
           <p class="para">
            Corresponds to the read preference&#039;s <code class="parameter">mode</code>
            parameter. Defaults to <code class="literal">&quot;primary&quot;</code>. For details,
            see <span class="classname"><a href="class.mongodb-driver-readpreference.html" class="classname">MongoDB\Driver\ReadPreference</a></span>.
           </p>
          </td>
         </tr>

         <tr>
          <td>readPreferenceTags</td>
          <td><span class="type">array</span></td>
          <td>
           <p class="para">
            Corresponds to the read preference&#039;s <code class="parameter">tagSets</code>
            parameter. Tag sets allow you to target read operations to specific
            members of a replica set. For details, see
            <span class="classname"><a href="class.mongodb-driver-readpreference.html" class="classname">MongoDB\Driver\ReadPreference</a></span>.
           </p>
           <blockquote class="note"><p><strong class="note">注意</strong>: 
            <span class="simpara">
             When not specified in the URI string, this option is expressed as
             an array consistent with the format expected by
             <span class="function"><a href="mongodb-driver-readpreference.construct.html" class="function">MongoDB\Driver\ReadPreference::__construct()</a></span>.
            </span>
           </p></blockquote>
          </td>
         </tr>

         <tr>
          <td>replicaSet</td>
          <td><span class="type">string</span></td>
          <td>
           <p class="para">
            Specifies the name of the replica set.
           </p>
          </td>
         </tr>

         <tr>
          <td>retryReads</td>
          <td><span class="type">bool</span></td>
          <td>
           <p class="para">
            Specifies whether or not the driver should automatically retry
            certain read operations that fail due to transient network errors
            or replica set elections. This functionality requires MongoDB 3.6+.
            Defaults to <strong><code>true</code></strong>.
           </p>
           <p class="para">
            See the
            <a href="https://github.com/mongodb/specifications/blob/master/source/retryable-reads/retryable-reads.rst" class="link external">&raquo;&nbsp;Retryable Reads Specification</a>
            for more information.
           </p>
          </td>
         </tr>

         <tr>
          <td>retryWrites</td>
          <td><span class="type">bool</span></td>
          <td>
           <p class="para">
            Specifies whether or not the driver should automatically retry
            certain write operations that fail due to transient network errors
            or replica set elections. This functionality requires MongoDB 3.6+.
            Defaults to <strong><code>true</code></strong>.
           </p>
           <p class="para">
            See
            <a href="https://www.mongodb.com/docs/manual/core/retryable-writes/" class="link external">&raquo;&nbsp;Retryable Writes</a>
            in the MongoDB manual for more information.
           </p>
          </td>
         </tr>

         <tr>
          <td>safe</td>
          <td><span class="type">bool</span></td>
          <td>
           <p class="para">
            If <strong><code>true</code></strong>, specifies <code class="literal">1</code> for the default write
            concern&#039;s <code class="parameter">w</code> parameter. If <strong><code>false</code></strong>,
            <code class="literal">0</code> is specified. For details, see
            <span class="classname"><a href="class.mongodb-driver-writeconcern.html" class="classname">MongoDB\Driver\WriteConcern</a></span>.
           </p>
           <p class="para">
            This option is deprecated and should not be used.
           </p>
          </td>
         </tr>

         <tr id="mongodb-driver-manager.construct-urioptions.serverselectiontimeoutms">
          <td>serverSelectionTimeoutMS</td>
          <td><span class="type">int</span></td>
          <td>
           <p class="para">
            Specifies how long in milliseconds to block for server selection
            before throwing an exception. Defaults to 30,000 milliseconds.
           </p>
          </td>
         </tr>

         <tr>
          <td>serverSelectionTryOnce</td>
          <td><span class="type">bool</span></td>
          <td>
           <p class="para">
            When <strong><code>true</code></strong>, instructs the driver to scan the MongoDB deployment
            exactly once after server selection fails and then either select a
            server or raise an error. When <strong><code>false</code></strong>, the driver blocks and
            searches for a server up to the
            <code class="literal">&quot;serverSelectionTimeoutMS&quot;</code> value. Defaults to
            <strong><code>true</code></strong>.
           </p>
          </td>
         </tr>

         <tr>
          <td>socketCheckIntervalMS</td>
          <td><span class="type">int</span></td>
          <td>
           <p class="para">
            If a socket has not been used recently, the driver must check it via
            a <code class="literal">hello</code> command before using it for any
            operation. Defaults to 5,000 milliseconds.
           </p>
          </td>
         </tr>

         <tr>
          <td>socketTimeoutMS</td>
          <td><span class="type">int</span></td>
          <td>
           <p class="para">
            The time in milliseconds to attempt a send or receive on a socket
            before timing out. Defaults to 300,000 milliseconds (i.e. five
            minutes).
           </p>
          </td>
         </tr>

         <tr>
          <td>srvMaxHosts</td>
          <td><span class="type">int</span></td>
          <td>
           <p class="para">
            The maximum number of SRV results to randomly select when initially
            populating the seedlist or, during SRV polling, adding new hosts to
            the topology. Defaults to <code class="literal">0</code> (i.e. no maximum).
           </p>
          </td>
         </tr>

         <tr>
          <td>srvServiceName</td>
          <td><span class="type">string</span></td>
          <td>
           <p class="para">
            The service name to use for SRV lookup in initial DNS seedlist
            discovery and SRV polling. Defaults to <code class="literal">&quot;mongodb&quot;</code>.
           </p>
          </td>
         </tr>

         <tr>
          <td>ssl</td>
          <td><span class="type">bool</span></td>
          <td>
           <p class="para">
            Initiates the connection with TLS/SSL if <strong><code>true</code></strong>. Defaults to
            <strong><code>false</code></strong>.
           </p>
           <p class="para">
            This option is a deprecated alias for the <code class="literal">&quot;tls&quot;</code>
            URI option.
           </p>
          </td>
         </tr>

         <tr>
          <td>tls</td>
          <td><span class="type">bool</span></td>
          <td>
           <p class="para">
            Initiates the connection with TLS/SSL if <strong><code>true</code></strong>. Defaults to
            <strong><code>false</code></strong>.
           </p>
          </td>
         </tr>

         <tr>
          <td>tlsAllowInvalidCertificates</td>
          <td><span class="type">bool</span></td>
          <td>
           <p class="para">
            Specifies whether or not the driver should error when the server&#039;s
            TLS certificate is invalid. Defaults to <strong><code>false</code></strong>.
           </p>
           <div class="warning"><strong class="warning">警告</strong>
            <p class="simpara">
             Disabling certificate validation creates a vulnerability.
            </p>
           </div>
          </td>
         </tr>

         <tr>
          <td>tlsAllowInvalidHostnames</td>
          <td><span class="type">bool</span></td>
          <td>
           <p class="para">
            Specifies whether or not the driver should error when there is a
            mismatch between the server&#039;s hostname and the hostname specified by
            the TLS certificate. Defaults to <strong><code>false</code></strong>.
           </p>
           <div class="warning"><strong class="warning">警告</strong>
            <p class="simpara">
             Disabling certificate validation creates a vulnerability. Allowing
             invalid hostnames may expose the driver to a
             <a href="https://en.wikipedia.org/wiki/Man-in-the-middle_attack" class="link external">&raquo;&nbsp;man-in-the-middle attack</a>.
            </p>
           </div>
          </td>
         </tr>

         <tr>
          <td>tlsCAFile</td>
          <td><span class="type">string</span></td>
          <td>
           <p class="para">
            Path to file with either a single or bundle of certificate
            authorities to be considered trusted when making a TLS connection.
            The system certificate store will be used by default.
           </p>
          </td>
         </tr>

         <tr>
          <td>tlsCertificateKeyFile</td>
          <td><span class="type">string</span></td>
          <td>
           <p class="para">
            Path to the client certificate file or the client private key file;
            in the case that they both are needed, the files should be
            concatenated.
           </p>
          </td>
         </tr>

         <tr>
          <td>tlsCertificateKeyFilePassword</td>
          <td><span class="type">string</span></td>
          <td>
           <p class="para">
            Password to decrypt the client private key (i.e.
            <code class="literal">&quot;tlsCertificateKeyFile&quot;</code> URI option) to be used
            for TLS connections.
           </p>
          </td>
         </tr>

         <tr>
          <td>tlsDisableCertificateRevocationCheck</td>
          <td><span class="type">bool</span></td>
          <td>
           <p class="para">
            If <strong><code>true</code></strong>, the driver will not attempt to check certificate
            revocation status (e.g. OCSP, CRL). Defaults to <strong><code>false</code></strong>.
           </p>
          </td>
         </tr>

         <tr>
          <td>tlsDisableOCSPEndpointCheck</td>
          <td><span class="type">bool</span></td>
          <td>
           <p class="para">
            If <strong><code>true</code></strong>, the driver will not attempt to contact an OCSP responder
            endpoint if needed (i.e. an OCSP response is not stapled). Defaults
            to <strong><code>false</code></strong>.
           </p>
          </td>
         </tr>

         <tr>
          <td>tlsInsecure</td>
          <td><span class="type">bool</span></td>
          <td>
           <p class="para">
            Relax TLS constraints as much as possible. Specifying <strong><code>true</code></strong> for
            this option has the same effect as specifying <strong><code>true</code></strong> for both the
            <code class="literal">&quot;tlsAllowInvalidCertificates&quot;</code> and
            <code class="literal">&quot;tlsAllowInvalidHostnames&quot;</code> URI options. Defaults
            to <strong><code>false</code></strong>.
           </p>
           <div class="warning"><strong class="warning">警告</strong>
            <p class="simpara">
             Disabling certificate validation creates a vulnerability. Allowing
             invalid hostnames may expose the driver to a
             <a href="https://en.wikipedia.org/wiki/Man-in-the-middle_attack" class="link external">&raquo;&nbsp;man-in-the-middle attack</a>.
            </p>
           </div>
          </td>
         </tr>

         <tr>
          <td>username</td>
          <td><span class="type">string</span></td>
          <td>
           The username for the user being authenticated. This option is useful
           if the username contains special characters, which would otherwise
           need to be URL encoded for the connection URI.
          </td>
         </tr>

         <tr>
          <td>w</td>
          <td><span class="type"><span class="type">int</span>|<span class="type">string</span></span></td>
          <td>
           <p class="para">
            Corresponds to the default write concern&#039;s <code class="parameter">w</code>
            parameter. For details, see
            <span class="classname"><a href="class.mongodb-driver-writeconcern.html" class="classname">MongoDB\Driver\WriteConcern</a></span>.
           </p>
          </td>
         </tr>

         <tr>
          <td>wTimeoutMS</td>
          <td><span class="type"><span class="type">int</span>|<span class="type">string</span></span></td>
          <td>
           <p class="para">
            Corresponds to the default write concern&#039;s
            <code class="parameter">wtimeout</code> parameter. Specifies a time limit,
            in milliseconds, for the write concern. For details, see
            <span class="classname"><a href="class.mongodb-driver-writeconcern.html" class="classname">MongoDB\Driver\WriteConcern</a></span>.
           </p>
           <p class="para">
            If specified, <code class="literal">wTimeoutMS</code> must be a signed 32-bit
            integer greater than or equal to zero.
           </p>
          </td>
         </tr>

         <tr>
          <td>zlibCompressionLevel</td>
          <td><span class="type">int</span></td>
          <td>
           <p class="para">
            Specifies the compression level to use for the zlib compressor. This
            option has no effect if <code class="literal">zlib</code> is not included in
            the <code class="literal">&quot;compressors&quot;</code> URI option. See the
            <a href="https://github.com/mongodb/specifications/blob/master/source/compression/OP_COMPRESSED.rst#zlibcompressionlevel" class="link external">&raquo;&nbsp;Driver Compression Specification</a>
            for more information.
           </p>
          </td>
         </tr>

        </tbody>
       
      </table>

     </p>
    </dd>

   
   
    <dt id="mongodb-driver-manager.construct-driveroptions"><code class="parameter">driverOptions</code></dt>

    <dd>

     <p class="para">
      <table class="doctable table">
       <caption><strong>driverOptions</strong></caption>
       
        <thead>
         <tr>
          <th>Option</th>
          <th>Type</th>
          <th>Description</th>
         </tr>

        </thead>

        <tbody class="tbody">
         <tr>
          <td>allow_invalid_hostname</td>
          <td><span class="type">bool</span></td>
          <td>
           <p class="para">
            Disables hostname validation if <strong><code>true</code></strong>. Defaults to <strong><code>false</code></strong>.
           </p>
           <p class="para">
            Allowing invalid hostnames may expose the driver to a
            <a href="https://en.wikipedia.org/wiki/Man-in-the-middle_attack" class="link external">&raquo;&nbsp;man-in-the-middle attack</a>.
           </p>
           <p class="para">
            This option is a deprecated alias for the
            <code class="literal">&quot;tlsAllowInvalidHostnames&quot;</code> URI option.
           </p>
          </td>
         </tr>

         <tr>
          <td>autoEncryption</td>
          <td><span class="type">array</span></td>
          <td>
           <p class="para">
            Provides options to enable automatic client-side field level
            encryption.
           </p>
           <blockquote class="note"><p><strong class="note">注意</strong>: 
            <p class="para">
             Automatic encryption is an enterprise-only feature that only
             applies to operations on a collection. Automatic encryption is not
             supported for operations on a database or view, and operations that
             are not bypassed will result in error (see
             <a href="https://github.com/mongodb/specifications/blob/master/source/client-side-encryption/client-side-encryption.rst#libmongocrypt-auto-encryption-allow-list" class="link external">&raquo;&nbsp;libmongocrypt: Auto Encryption Allow-List</a>). To bypass automatic encryption
             for all operations, set <code class="literal">bypassAutoEncryption</code> to
             <strong><code>true</code></strong>.
            </p>
            <p class="para">
             Automatic encryption requires the authenticated user to have the
             <a href="https://www.mongodb.com/docs/manual/reference/command/listCollections/#required-access" class="link external">&raquo;&nbsp;listCollections</a>
             privilege action.
            </p>
            <p class="para">
             Explicit encryption/decryption and automatic decryption is a
             community feature. The driver can still automatically decrypt when
             <code class="literal">bypassAutoEncryption</code> is <strong><code>true</code></strong>.
            </p>
           </p></blockquote>
           <p class="para">
            The following options are supported:

            <table class="doctable table">
             <caption><strong>Options for automatic encryption</strong></caption>
             
              <thead>
               <tr>
                <th>Option</th>
                <th>Type</th>
                <th>Description</th>
               </tr>

              </thead>

              <tbody class="tbody">
               
         <tr>
          <td>keyVaultClient</td>
          <td><span class="classname"><a href="class.mongodb-driver-manager.html" class="classname">MongoDB\Driver\Manager</a></span></td>
          <td>The Manager used to route data key queries to a separate MongoDB cluster. By default, the current Manager and cluster is used.</td>
         </tr>


               
         <tr>
          <td>keyVaultNamespace</td>
          <td><span class="type">string</span></td>
          <td>A fully qualified namespace (e.g. <code class="literal">&quot;databaseName.collectionName&quot;</code>) denoting the collection that contains all data keys used for encryption and decryption.</td>
         </tr>


               
         <tr>
          <td>kmsProviders</td>
          <td><span class="type">array</span></td>
          <td>
           <p class="para">
            A document containing the configuration for one or more KMS providers, which are used to encrypt data keys. Supported providers include <code class="literal">&quot;aws&quot;</code>, <code class="literal">&quot;azure&quot;</code>, <code class="literal">&quot;gcp&quot;</code>, <code class="literal">&quot;kmip&quot;</code>, and <code class="literal">&quot;local&quot;</code> and at least one must be specified.
           </p>
           <p class="para">
            The format for <code class="literal">&quot;aws&quot;</code> is as follows:
           </p>
           <div class="example-contents">
<div class="javascriptcode"><pre class="javascriptcode">aws: {
    accessKeyId: &lt;string&gt;,
    secretAccessKey: &lt;string&gt;
}</pre>
</div>
           </div>

           <p class="para">
            The format for <code class="literal">&quot;azure&quot;</code> is as follows:
           </p>
           <div class="example-contents">
<div class="javascriptcode"><pre class="javascriptcode">azure: {
    tenantId: &lt;string&gt;,
    clientId: &lt;string&gt;,
    clientSecret: &lt;string&gt;,
    identityPlatformEndpoint: &lt;optional string&gt; // Defaults to &quot;login.microsoftonline.com&quot;
}</pre>
</div>
           </div>

           <p class="para">
            The format for <code class="literal">&quot;gcp&quot;</code> is as follows:
           </p>
           <div class="example-contents">
<div class="javascriptcode"><pre class="javascriptcode">gcp: {
    email: &lt;string&gt;,
    privateKey: &lt;base64 string&gt;|&lt;MongoDB\BSON\Binary&gt;,
    endpoint: &lt;optional string&gt; // Defaults to &quot;oauth2.googleapis.com&quot;
}</pre>
</div>
           </div>

           <p class="para">
            The format for <code class="literal">&quot;kmip&quot;</code> is as follows:
           </p>
           <div class="example-contents">
<div class="javascriptcode"><pre class="javascriptcode">kmip: {
    endpoint: &lt;string&gt;
}</pre>
</div>
           </div>

           <p class="para">
            The format for <code class="literal">&quot;local&quot;</code> is as follows:
           </p>
           <div class="example-contents">
<div class="javascriptcode"><pre class="javascriptcode">local: {
    // 96-byte master key used to encrypt/decrypt data keys
    key: &lt;base64 string&gt;|&lt;MongoDB\BSON\Binary&gt;
}</pre>
</div>
           </div>

          </td>
         </tr>


               
         <tr>
          <td>tlsOptions</td>
          <td><span class="type">array</span></td>
          <td>
           <p class="para">
            A document containing the TLS configuration for one or more KMS providers. Supported providers include <code class="literal">&quot;aws&quot;</code>, <code class="literal">&quot;azure&quot;</code>, <code class="literal">&quot;gcp&quot;</code>, and <code class="literal">&quot;kmip&quot;</code>. All providers support the following options:
           </p>
           <div class="example-contents">
<div class="javascriptcode"><pre class="javascriptcode">&lt;provider&gt;: {
    tlsCaFile: &lt;optional string&gt;,
    tlsCertificateKeyFile: &lt;optional string&gt;,
    tlsCertificateKeyFilePassword: &lt;optional string&gt;
}</pre>
</div>
           </div>

          </td>
         </tr>


               <tr>
                <td>schemaMap</td>
                <td><span class="type"><span class="type">array</span>|<span class="type">object</span></span></td>
                <td>
                 <p class="para">
                  Map of collection namespaces to a local JSON schema. This is
                  used to configure automatic encryption. See
                  <a href="https://www.mongodb.com/docs/manual/reference/security-client-side-automatic-json-schema/" class="link external">&raquo;&nbsp;Automatic Encryption Rules</a>
                  in the MongoDB manual for more information. It is an error to
                  specify a collection in both <code class="literal">schemaMap</code> and
                  <code class="literal">encryptedFieldsMap</code>.
                 </p>
                 <blockquote class="note"><p><strong class="note">注意</strong>: 
                  <span class="simpara">
                   Supplying a <code class="literal">schemaMap</code> provides more
                   security than relying on JSON schemas obtained from the
                   server. It protects against a malicious server advertising a
                   false JSON schema, which could trick the client into sending
                   unencrypted data that should be encrypted.
                  </span>
                 </p></blockquote>
                 <blockquote class="note"><p><strong class="note">注意</strong>: 
                  <span class="simpara">
                   Schemas supplied in the <code class="literal">schemaMap</code> only
                   apply to configuring automatic encryption for client side
                   encryption. Other validation rules in the JSON schema will
                   not be enforced by the driver and will result in an error.
                  </span>
                 </p></blockquote>
                </td>
               </tr>

               <tr>
                <td>bypassAutoEncryption</td>
                <td><span class="type">bool</span></td>
                <td>
                 If <strong><code>true</code></strong>, <code class="literal">mongocryptd</code> will not be spawned
                 automatically. This is used to disable automatic encryption.
                 Defaults to <strong><code>false</code></strong>.
                </td>
               </tr>

               <tr>
                <td>bypassQueryAnalysis</td>
                <td><span class="type">bool</span></td>
                <td>
                 <p class="para">
                  If <strong><code>true</code></strong>, automatic analysis of outgoing commands will be
                  disabled and <code class="literal">mongocryptd</code> will not be
                  spawned automatically. This enables the use case of explicit
                  encryption for querying indexed fields without requiring the
                  enterprise licensed <code class="literal">crypt_shared</code> library or
                  <code class="literal">mongocryptd</code> process. Defaults to <strong><code>false</code></strong>.
                 </p>
                 
   <blockquote class="note"><p><strong class="note">注意</strong>: 
    <span class="simpara">
     Queryable Encryption is in public preview and available for evaluation
     purposes. It is not yet recommended for production deployments as breaking
     changes may be introduced. See the <a href="https://www.mongodb.com/blog/post/mongodb-releases-queryable-encryption-preview/" class="link external">&raquo;&nbsp;Queryable Encryption Preview</a> blog post for more information.
    </span>
   </p></blockquote>

                </td>
               </tr>

               <tr>
                <td>encryptedFieldsMap</td>
                <td><span class="type"><span class="type">array</span>|<span class="type">object</span></span></td>
                <td>
                 <p class="para">
                  Map of collection namespaces to an
                  <code class="literal">encryptedFields</code> document. This is used to
                  configure queryable encryption. See
                  <a href="https://www.mongodb.com/docs/v6.0/core/queryable-encryption/fundamentals/encrypt-and-query/" class="link external">&raquo;&nbsp;Field Encryption and Queryability</a>
                  in the MongoDB manual for more information. It is an error to
                  specify a collection in both
                  <code class="literal">encryptedFieldsMap</code> and
                  <code class="literal">schemaMap</code>.
                 </p>
                 <blockquote class="note"><p><strong class="note">注意</strong>: 
                  <span class="simpara">
                   Supplying an <code class="literal">encryptedFieldsMap</code> provides
                   more security than relying on an encrypted fields
                   <code class="literal">encryptedFields</code> obtained from the server.
                   It protects against a malicious server advertising a false
                   <code class="literal">encryptedFields</code>.
                  </span>
                 </p></blockquote>
                 
   <blockquote class="note"><p><strong class="note">注意</strong>: 
    <span class="simpara">
     Queryable Encryption is in public preview and available for evaluation
     purposes. It is not yet recommended for production deployments as breaking
     changes may be introduced. See the <a href="https://www.mongodb.com/blog/post/mongodb-releases-queryable-encryption-preview/" class="link external">&raquo;&nbsp;Queryable Encryption Preview</a> blog post for more information.
    </span>
   </p></blockquote>

                </td>
               </tr>

               <tr>
                <td>extraOptions</td>
                <td><span class="type">array</span></td>
                <td>
                 <p class="para">
                  The <code class="literal">extraOptions</code> relate to the
                  <code class="literal">mongocryptd</code> process. The following options
                  are supported:
                 </p>
                 <ul class="simplelist">
                  <li class="member"><code class="literal">mongocryptdURI</code> (<span class="type">string</span>): URI to connect to an existing <code class="literal">mongocryptd</code> process. Defaults to <code class="literal">&quot;mongodb://localhost:27020&quot;</code>.</li>
                  <li class="member"><code class="literal">mongocryptdBypassSpawn</code> (<span class="type">bool</span>): If <strong><code>true</code></strong>, prevent the driver from spawning <code class="literal">mongocryptd</code>. Defaults to <strong><code>false</code></strong>.</li>
                  <li class="member"><code class="literal">mongocryptdSpawnPath</code> (<span class="type">string</span>): Absolute path to search for <code class="literal">mongocryptd</code> binary. Defaults to empty string and consults system paths.</li>
                  <li class="member"><code class="literal">mongocryptdSpawnArgs</code> (<span class="type">array</span>): Array of string arguments to pass to <code class="literal">mongocryptd</code> when spawning. Defaults to <code class="literal">[&quot;--idleShutdownTimeoutSecs=60&quot;]</code>.</li>
                  <li class="member"><code class="literal">cryptSharedLibPath</code> (<span class="type">string</span>): Absolute path to <code class="literal">crypt_shared</code> shared library. Defaults to empty string and consults system paths.</li>
                  <li class="member"><code class="literal">cryptSharedLibRequired</code> (<span class="type">bool</span>): If <strong><code>true</code></strong>, require the driver to load <code class="literal">crypt_shared</code>. Defaults to <strong><code>false</code></strong>.</li>
                 </ul>
                 <p class="para">
                  See the <a href="https://github.com/mongodb/specifications/blob/master/source/client-side-encryption/client-side-encryption.rst#extraoptions" class="link external">&raquo;&nbsp;Client-Side Encryption Specification</a> for more information.
                 </p>
                </td>
               </tr>

              </tbody>
             
            </table>

           </p>

           <blockquote class="note"><p><strong class="note">注意</strong>: 
            <span class="simpara">
             Automatic encryption is an enterprise only feature that only
             applies to operations on a collection. Automatic encryption is not
             supported for operations on a database or view, and operations that
             are not bypassed will result in error. To bypass automatic
             encryption for all operations, set <code class="literal">bypassAutoEncryption=true</code>
             in <code class="literal">autoEncryption</code>. For more information on
             allowed operations, see the
             <a href="https://github.com/mongodb/specifications/blob/master/source/client-side-encryption/client-side-encryption.rst#libmongocrypt-auto-encryption-whitelist" class="link external">&raquo;&nbsp;Client-Side Encryption Specification</a>.
            </span>
           </p></blockquote>
          </td>
         </tr>

         <tr>
          <td>ca_dir</td>
          <td><span class="type">string</span></td>
          <td>
           <p class="para">
            Path to a correctly hashed certificate directory. The system
            certificate store will be used by default.
           </p>
          </td>
         </tr>

         <tr>
          <td>ca_file</td>
          <td><span class="type">string</span></td>
          <td>
           <p class="para">
            Path to file with either a single or bundle of certificate
            authorities to be considered trusted when making a TLS connection.
            The system certificate store will be used by default.
           </p>
           <p class="para">
            This option is a deprecated alias for the
            <code class="literal">&quot;tlsCAFile&quot;</code> URI option.
           </p>
          </td>
         </tr>

         <tr>
          <td>context</td>
          <td><span class="type">resource</span></td>
          <td>
           <p class="para">
            <a href="context.ssl.html" class="link">SSL context options</a> to be used as
            fallbacks if a driver option or its equivalent URI option, if any,
            is not specified. Note that the driver does not consult the default
            stream context (i.e.
            <span class="function"><a href="function.stream-context-get-default.html" class="function">stream_context_get_default()</a></span>). The following
            context options are supported:
           </p>

           <table class="doctable table">
            <caption><strong>SSL context option fallbacks</strong></caption>
            
             <thead>
              <tr>
               <th>Driver option</th>
               <th>Context option (fallback)</th>
              </tr>

             </thead>

             <tbody class="tbody">
              <tr>
               <td>ca_dir</td>
               <td>capath</td>
              </tr>

              <tr>
               <td>ca_file</td>
               <td>cafile</td>
              </tr>

              <tr>
               <td>pem_file</td>
               <td>local_cert</td>
              </tr>

              <tr>
               <td>pem_pwd</td>
               <td>passphrase</td>
              </tr>

              <tr>
               <td>weak_cert_validation</td>
               <td>allow_self_signed</td>
              </tr>

             </tbody>
            
           </table>

           <p class="para">
            This option is supported for backwards compatibility, but should be
            considered deprecated.
           </p>
          </td>
         </tr>

         <tr>
          <td>crl_file</td>
          <td><span class="type">string</span></td>
          <td>Path to a certificate revocation list file.</td>
         </tr>

         <tr>
          <td>disableClientPersistence</td>
          <td><span class="type">bool</span></td>
          <td>
           <p class="para">
            If <strong><code>true</code></strong>, this Manager will use a new libmongoc client, which will
            not be persisted or shared with other Manager objects. When this
            Manager object is freed, its client will be destroyed and any
            connections will be closed. Defaults to <strong><code>false</code></strong>.
           </p>
           <blockquote class="note"><p><strong class="note">注意</strong>: 
            <span class="simpara">
             Disabling client persistence is not generally recommended.
            </span>
           </p></blockquote>
          </td>
         </tr>

         <tr>
          <td>driver</td>
          <td><span class="type">array</span></td>
          <td>
           <p class="para">
            Allows custom drivers to append their own metadata to the server
            handshake. By default, the driver submits its own name, version, and
            platform (i.e. PHP version) in the handshake. Custom drivers can
            specify strings for the <code class="literal">&quot;name&quot;</code>,
            <code class="literal">&quot;version&quot;</code>, and
            <code class="literal">&quot;platform&quot;</code> keys of this array, which will be
            appended to the respective field(s) in the handshake document.
           </p>
           <blockquote class="note"><p><strong class="note">注意</strong>: 
            <span class="simpara">
             Handshake information is limited to 512 bytes. The driver will
             truncate handshake data to fit within this 512-byte string. Drivers
             and ODMs are encouraged to keep their own metadata concise.
            </span>
           </p></blockquote>
          </td>
         </tr>

         <tr>
          <td>pem_file</td>
          <td><span class="type">string</span></td>
          <td>
           <p class="para">
            Path to a PEM encoded certificate to use for client authentication.
           </p>
           <p class="para">
            This option is a deprecated alias for the
            <code class="literal">&quot;tlsCertificateKeyFile&quot;</code> URI option.
           </p>
          </td>
         </tr>

         <tr>
          <td>pem_pwd</td>
          <td><span class="type">string</span></td>
          <td>
           <p class="para">
            Passphrase for the PEM encoded certificate (if applicable).
           </p>
           <p class="para">
            This option is a deprecated alias for the
            <code class="literal">&quot;tlsCertificateKeyFilePassword&quot;</code> URI option.
           </p>
          </td>
         </tr>

         <tr>
          <td>serverApi</td>
          <td><span class="classname"><strong class="classname">MongoDB\Driver\ServerApi</strong></span></td>
          <td>
           <p class="para">
            This option is used to declare a server API version for the manager.
            If omitted, no API version is declared.
           </p>
          </td>
         </tr>

         <tr>
          <td>weak_cert_validation</td>
          <td><span class="type">bool</span></td>
          <td>
           <p class="para">
            Disables certificate validation if <strong><code>true</code></strong>. Defaults to <strong><code>false</code></strong>
           </p>
           <p class="para">
            This option is a deprecated alias for the
            <code class="literal">&quot;tlsAllowInvalidCertificates&quot;</code> URI option.
           </p>
          </td>
         </tr>

        </tbody>
       
      </table>

     </p>
    </dd>

   
  </dl>

 </div>


 <div class="refsect1 errors" id="refsect1-mongodb-driver-manager.construct-errors">
  <h3 class="title">错误／异常</h3>
  <ul class="simplelist">
   <li class="member">Throws <span class="classname"><a href="class.mongodb-driver-exception-invalidargumentexception.html" class="classname">MongoDB\Driver\Exception\InvalidArgumentException</a></span> on argument parsing errors.</li>
   <li class="member">Throws <span class="classname"><a href="class.mongodb-driver-exception-runtimeexception.html" class="classname">MongoDB\Driver\Exception\RuntimeException</a></span> if the <code class="parameter">uri</code> format is invalid</li>
  </ul>
 </div>


 <div class="refsect1 changelog" id="refsect1-mongodb-driver-manager.construct-changelog">
  <h3 class="title">更新日志</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>版本</th>
       <th>说明</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>PECL mongodb 1.14.0</td>
       <td>
        <p class="para">
         Added the <code class="literal">&quot;bypassQueryAnalysis&quot;</code> and
         <code class="literal">&quot;encryptedFieldsMap&quot;</code> auto encryption options.
         Additional options pertaining to <code class="literal">crypt_shared</code> are
         now supported in the <code class="literal">&quot;extraOptions&quot;</code> auto encryption
         option.
        </p>
       </td>
      </tr>

      <tr>
       <td>PECL mongodb 1.13.0</td>
       <td>
        <p class="para">
         Added the <code class="literal">&quot;srvMaxHosts&quot;</code> and
         <code class="literal">&quot;srvServiceName&quot;</code> URI options.
        </p>
       </td>
      </tr>

      <tr>
       <td>PECL mongodb 1.12.0</td>
       <td>
        <p class="para">
         KMIP is now supported as a KMS provider for client-side encryption and
         may be configured in the <code class="literal">&quot;kmsProviders&quot;</code> field of the
         <code class="literal">&quot;autoEncryption&quot;</code> driver option. Additionally, TLS
         options for KMS providers may now be configured in the
         <code class="literal">&quot;tlsOptions&quot;</code> field of the
         <code class="literal">&quot;autoEncryption&quot;</code> driver option.
        </p>
       </td>
      </tr>

      <tr>
       <td>PECL mongodb 1.11.0</td>
       <td>
        <p class="para">
         Added the <code class="literal">&quot;loadBalanced&quot;</code> URI option.
        </p>
       </td>
      </tr>

      <tr>
       <td>PECL mongodb 1.10.0</td>
       <td>
        <p class="para">
         Added the <code class="literal">&quot;disableClientPersistence&quot;</code> driver option.
        </p>
        <p class="para">
         Azure and GCP are now supported as KMS providers for client-side
         encryption and may be configured in the
         <code class="literal">&quot;kmsProviders&quot;</code> field of the
         <code class="literal">&quot;autoEncryption&quot;</code> driver option. Base64-encoded
         strings are now accepted as an alternative to
         <span class="classname"><a href="class.mongodb-bson-binary.html" class="classname">MongoDB\BSON\Binary</a></span> for options within
         <code class="literal">&quot;kmsProviders&quot;</code>.
        </p>
       </td>
      </tr>

      <tr>
       <td>PECL mongodb 1.8.0</td>
       <td>
        <p class="para">
         Added the <code class="literal">&quot;directConnection&quot;</code>,
         <code class="literal">&quot;tlsDisableCertificateRevocationCheck&quot;</code>, and
         <code class="literal">&quot;tlsDisableOCSPEndpointCheck&quot;</code> URI options.
        </p>
        <p class="para">
         Added the <code class="literal">&quot;driver&quot;</code> driver option.
        </p>
       </td>
      </tr>

      <tr>
       <td>PECL mongodb 1.7.0</td>
       <td>
        <p class="para">
         Added the <code class="literal">&quot;autoEncryption&quot;</code> driver option.
        </p>
        <p class="para">
         Specifying any SSL or TLS option via the <code class="parameter">driverOptions</code>
         parameter will now implicitly enable TLS, as is done for the
         corresponding URI options.
        </p>
       </td>
      </tr>

      <tr>
       <td>PECL mongodb 1.6.0</td>
       <td>
        <p class="para">
         Added the <code class="literal">&quot;retryReads&quot;</code>, <code class="literal">&quot;tls&quot;</code>,
         <code class="literal">&quot;tlsAllowInvalidCertificates&quot;</code>,
         <code class="literal">&quot;tlsAllowInvalidHostnames&quot;</code>,
         <code class="literal">&quot;tlsCAFile&quot;</code>,
         <code class="literal">&quot;tlsCertificateKeyFile&quot;</code>,
         <code class="literal">&quot;tlsCertificateKeyFilePassword&quot;</code>, and
         <code class="literal">&quot;tlsInsecure&quot;</code> URI options.
        </p>
        <p class="para">
         The <code class="literal">&quot;retryWrites&quot;</code> URI option defaults to <strong><code>true</code></strong>.
        </p>
        <p class="para">
         Specifying any SSL or TLS URI option via the connection string or
         <code class="parameter">uriOptions</code> parameter will now implicitly enable
         TLS unless <code class="literal">ssl</code> or <code class="literal">tls</code> is <strong><code>false</code></strong>.
         TLS is <em class="emphasis">not</em> implicitly enabled for any options in
         the <code class="parameter">driverOptions</code> parameter, which is unchanged
         from previous versions.
        </p>
       </td>
      </tr>

      <tr>
       <td>PECL mongodb 1.5.0</td>
       <td>
        <p class="para">
         <code class="literal">&quot;wtimeoutMS&quot;</code> is now always validated and applied to
         the write concern. Previously, the option was ignored if
         <code class="literal">&quot;w&quot;</code> was &lt;= 1, since the timeout only applies to
         replication.
        </p>
       </td>
      </tr>

      <tr>
       <td>PECL mongodb 1.4.0</td>
       <td>
        <p class="para">
         Added the <code class="literal">&quot;compressors&quot;</code>,
         <code class="literal">&quot;retryWrites&quot;</code>, and
         <code class="literal">&quot;zlibCompressionLevel&quot;</code> URI options.
        </p>
       </td>
      </tr>

      <tr>
       <td>PECL mongodb 1.3.0</td>
       <td>
        <p class="para">
         The <code class="parameter">uriOptions</code> argument now accepts
         <code class="literal">&quot;authMechanism&quot;</code> and
         <code class="literal">&quot;authMechanismProperties&quot;</code> options. Previously, these
         options were only supported in the <code class="parameter">uri</code> argument.
        </p>
       </td>
      </tr>

      <tr>
       <td>PECL mongodb 1.2.0</td>
       <td>
        <p class="para">
         The <code class="parameter">uri</code> argument defaults to
         <code class="literal">&quot;mongodb://127.0.0.1/&quot;</code>. The default port remains
         <code class="literal">27017</code>.
        </p>
        <p class="para">
         Added the <code class="literal">&quot;appname&quot;</code> URI option.
        </p>
        <p class="para">
         Added the <code class="literal">&quot;allow_invalid_hostname&quot;</code>,
         <code class="literal">&quot;ca_file&quot;</code>, <code class="literal">&quot;ca_dir&quot;</code>,
         <code class="literal">&quot;clr_file&quot;</code>, <code class="literal">&quot;pem_file&quot;</code>,
         <code class="literal">&quot;pem_pwd&quot;</code>, and
         <code class="literal">&quot;weak_cert_validation&quot;</code> driver options.
        </p>
        <p class="para">
         The PHP Streams API is no longer used for socket communication. The
         <code class="literal">&quot;connectTimeoutMS&quot;</code> URI option now defaults to 10
         seconds instead of
         <a href="filesystem.configuration.html#ini.default-socket-timeout" class="link">default_socket_timeout</a>
         in previous versions. Additionally, the driver no longer supports all
         <a href="context.ssl.html" class="link">SSL context options</a> via the
         <code class="literal">&quot;context&quot;</code> driver option.
        </p>
       </td>
      </tr>

      <tr>
       <td>PECL mongodb 1.1.0</td>
       <td>
        <p class="para">
         The <code class="parameter">uri</code> argument is optional and defaults to
         <code class="literal">&quot;mongodb://localhost:27017/&quot;</code>.
        </p>
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-mongodb-driver-manager.construct-examples">
  <h3 class="title">范例</h3>
  <div class="example" id="example-1295">
   <p><strong>示例 #1 <span class="function"><strong>MongoDB\Driver\Manager::__construct()</strong></span> basic examples</strong></p>
   <div class="example-contents"><p>Connecting to standalone MongoDB node:</p></div>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br />$manager&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">MongoDB</span><span style="color: #007700">\</span><span style="color: #0000BB">Driver</span><span style="color: #007700">\</span><span style="color: #0000BB">Manager</span><span style="color: #007700">(</span><span style="color: #DD0000">"mongodb://example.com:27017"</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

   <div class="example-contents"><p>
    Connecting to standalone MongoDB node via a Unix domain socket. The socket
    path may include special characters such as slashes and should be encoded
    with <span class="function"><a href="function.rawurlencode.html" class="function">rawurlencode()</a></span>.
   </p></div>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br />$manager&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">MongoDB</span><span style="color: #007700">\</span><span style="color: #0000BB">Driver</span><span style="color: #007700">\</span><span style="color: #0000BB">Manager</span><span style="color: #007700">(</span><span style="color: #DD0000">"mongodb://"&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">rawurlencode</span><span style="color: #007700">(</span><span style="color: #DD0000">"/tmp/mongodb-27017.sock"</span><span style="color: #007700">));<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

   <div class="example-contents"><p>Connecting to a replica set:</p></div>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br />$manager&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">MongoDB</span><span style="color: #007700">\</span><span style="color: #0000BB">Driver</span><span style="color: #007700">\</span><span style="color: #0000BB">Manager</span><span style="color: #007700">(</span><span style="color: #DD0000">"mongodb://rs1.example.com,rs2.example.com/?replicaSet=myReplicaSet"</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

   <div class="example-contents"><p>Connecting to a sharded cluster (i.e. one or more mongos instances):</p></div>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br />$manager&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">MongoDB</span><span style="color: #007700">\</span><span style="color: #0000BB">Driver</span><span style="color: #007700">\</span><span style="color: #0000BB">Manager</span><span style="color: #007700">(</span><span style="color: #DD0000">"mongodb://mongos1.example.com,mongos2.example.com/"</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

   <div class="example-contents"><p>Connecting to MongoDB with authentication credentials for a particular user and database:</p></div>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br />$manager&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">MongoDB</span><span style="color: #007700">\</span><span style="color: #0000BB">Driver</span><span style="color: #007700">\</span><span style="color: #0000BB">Manager</span><span style="color: #007700">(</span><span style="color: #DD0000">"mongodb://myusername:mypassword@example.com/?authSource=databaseName"</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>


   <div class="example-contents"><p>
    Connecting to MongoDB with authentication credentials for a particular
    user and database, where the username or password includes special
    characters (e.g. <code class="literal">@</code>, <code class="literal">:</code>,
    <code class="literal">%</code>). In the following example, the password string
    <code class="literal">myp@ss:w%rd</code> has been manually escaped; however,
    <span class="function"><a href="function.rawurlencode.html" class="function">rawurlencode()</a></span> may also be used to escape URI components
    that may contain special characters.
   </p></div>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br />$manager&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">MongoDB</span><span style="color: #007700">\</span><span style="color: #0000BB">Driver</span><span style="color: #007700">\</span><span style="color: #0000BB">Manager</span><span style="color: #007700">(</span><span style="color: #DD0000">"mongodb://myusername:myp%40ss%3Aw%25rd@example.com/?authSource=databaseName"</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>


   <div class="example-contents"><p>Connecting to MongoDB with X509 authentication:</p></div>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br />$manager&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">MongoDB</span><span style="color: #007700">\</span><span style="color: #0000BB">Driver</span><span style="color: #007700">\</span><span style="color: #0000BB">Manager</span><span style="color: #007700">(<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"mongodb://example.com/?ssl=true&amp;authMechanism=MONGODB-X509"</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;[],<br />&nbsp;&nbsp;&nbsp;&nbsp;[<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"pem_file"&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">"/path/to/client.pem"</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;]<br />);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

  </div>
 </div>


 <div class="refsect1 seealso" id="refsect1-mongodb-driver-manager.construct-seealso">
  <h3 class="title">参见</h3>
  <ul class="simplelist">
   <li class="member"><a href="mongodb.connection-handling.html" class="link">Connection handling and persistence</a></li>
   <li class="member"><a href="https://www.mongodb.com/docs/manual/reference/connection-string/" class="link external">&raquo;&nbsp;MongoDB Connection String Format</a></li>
  </ul>
 </div>


</div></div></div></body></html>